package com.item.yxlottery.yxlottery.adapter;

/*
 *------------------------------
 * @创建者      Administrator
 * @创建时间    2017/1/3 16:53
 * @文件描述    彩店列表adapter
 *------------------------------
 */

import android.content.Context;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.item.yxlottery.yxlottery.R;
import com.item.yxlottery.yxlottery.bean.StoreBean;
import com.item.yxlottery.yxlottery.utils.RedNumberUtil;
import com.item.yxlottery.yxlottery.utils.UrlUtil;

import java.text.DecimalFormat;
import java.util.List;

public class StoreListAdapter extends BaseQuickAdapter<StoreBean, BaseViewHolder> {
    private Context mContext;
    private List<StoreBean> mList;

    public StoreListAdapter(Context context, int layoutResId, List<StoreBean> data) {
        super(layoutResId, data);
        mContext = context;
        mList = data;
    }

    @Override
    protected void convert(BaseViewHolder helper, StoreBean item) {
        Glide.with(mContext).load(UrlUtil.getImageHomeUrl() + item.getStoreLogo()).into((ImageView) helper.getView(R.id.iv_item_store_image));
        helper.setText(R.id.tv_item_store_name, item.getStoreName())
                .setText(R.id.tv_item_store_distance, RedNumberUtil.numberAndText(("距离" + new DecimalFormat("#.00").format(Double.parseDouble(item.getDistance()) / 1000) + "公里"), 2, 0xffff0000))
                .setText(R.id.tv_item_store_sales, item.getSales() + "单").setText(R.id.tv_item_store_people, item.getOrders());
        View view = helper.getView(R.id.view_item_store_line);
        if (helper.getAdapterPosition() == mList.size() - 1) {
            view.setVisibility(View.INVISIBLE);
        } else {
            view.setVisibility(View.VISIBLE);
        }
    }
}
